package com.cndcare.msc.netty.controller;

import com.cndcare.msc.constants.Constants;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/netty/info")
public class NettyInfoController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/serverInfo")
    public Object serverInfo() throws Exception {
        String str = stringRedisTemplate.opsForValue().get(Constants.NETTY_SERVER_KEY);
        ObjectMapper objectMapper = new ObjectMapper();
        List list = objectMapper.readValue(str, List.class);

        return list;
    }

}
